<template>
  <div>
    <a-card :bordered='false'>
      <f-search-form :more='true' @searchHandler='searchTable'>
        <f-search-form-item label='部门' name='deptId' type='select' :data='api.dept.list' valueKey='deptId'
                            label-key='deptName' :params='queryParam'/>
        <f-search-form-item label='姓名' name='saleManName' />
        <f-search-form-item label='编号' name='saleManCode' slot='advanced' />
        <f-search-form-item label='电话' name='linkTel' slot='advanced' />
      </f-search-form>
      <f-table ref='table' rowKey='saleManId' :columns='columns' :multiple='false' :operator='operator' handler='deptSaleManPageListHandler' :params='queryParam' :api='api.saleMan'>
          <span slot="proLevel" slot-scope="text">
          <a-tag color="#2db7f5"  v-if='text==1'>是</a-tag>
          <a-tag v-if='text==0'>否</a-tag>
        </span>
          <span slot='deptManager' slot-scope='text, record, index'>
            <a-tag color='#108ee9' v-if='text==0'>否</a-tag>
            <a-tag color='#f50' v-if='text==1'>是</a-tag>
        </span>
        <span slot='salemanState' slot-scope='text, record, index'>
          <a-switch v-model='record.salemanState==1' checkedChildren='启用' unCheckedChildren='禁用'
                    @change='(checked) => setSalemanState(checked,record)' />
        </span>
        <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='$refs.drawer.showDrawer(record)'>编辑</a>
            <a-divider type='vertical' />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
<!--               <a-menu-item>
                <a href='javascript:;' @click='$refs.drawer.showDrawer(record)'>调整部门</a>
              </a-menu-item>
               <a-menu-item>
                <a href='javascript:;' @click='$refs.drawer.showDrawer(record)'>停用</a>
              </a-menu-item>-->
              <a-menu-item>
                <a href='javascript:;' @click='$refs.table.del(record)'>删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <saleman-drawer ref='drawer' @success='onLoad'></saleman-drawer>
    </a-card>
  </div>
</template>
<script>
import salemanDrawer from "./saleman_drawer.vue"
import api from "../js/api"

export default {
  name: "DeptManTableList",
  components: {
    salemanDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "添加",
      icon: "plus",
      that: this,
      handler: function(table, that) {
        const params = { "deptId": null }
        if (that.searchParams && that.searchParams.deptId) {
          params.deptId = that.searchParams.deptId
        }
        that.$refs.drawer.showDrawer(params)
      }
    })
    operator.push({
      name: "删除",
      icon: "delete",
      batch: true,
      handler: function(table) {
        table.remove()
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        isFlp:1
      },
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "姓名",
          align: "center",
          ellipsis: true,
          width: "80px",
          dataIndex: "saleManName"
        },
        {
          title: "部门",
          align: "center",
          width: "90px",
          dataIndex: "deptName"
        },
        {
          title: "职务",
          align: "center",
          width: "80px",
          dataIndex: "positionName"
        },
       
        {
          title: "负责人编码",
          align: "center",
          width: "60px",
          dataIndex: "headCode"
        },
        {
          title: "职务编码",
          align: "center",
          width: "60px",
          dataIndex: "positionCode"
        },
        {
          title: "招募人",
          align: "center",
          width: "70px",
          dataIndex: "parentName"
        },
        {
          title: "省级",
          align: "center",
          width:"60px",
          sorter:true,
          dataIndex: "proLevel",
          scopedSlots: { customRender: "proLevel" },
        },
        {
          title: "联系电话",
          align: "center",
          width: "60px",
          dataIndex: "linkTel"
        },
        {
          title: "状态",
          align: "center",
          scopedSlots: { customRender: "salemanState" },
          width: "80px",
          dataIndex: "salemanState"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    //设置状态
    setSalemanState(check, record) {
      this.http.post(this, {
        url: this.api.saleMan.setSalemanState,
        data: {
          ids: record.saleManId,
          salemanState: Number(check)
        },
        success(me, data) {
          record.salemanState = data
        }
      })
    },
    onLoad() {
      this.$refs.table.refresh()
    },
    searchTable(searchParams) {
      this.searchParams = searchParams
      this.$refs.table.refresh(true, searchParams)
    }
  }
}
</script>
